# coding:utf8
"""
插入排序和冒泡排序的区别在于：

插入排序的前提是：左边是有序的数列
而冒泡排序：相邻的值进行交换，一共进行n次交换
"""
def insertion_sort(nums):
    for i in range(1, len(nums)):
        while i:
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
            i -= 1
    return nums


if __name__ == "__main__":
    nums = [3, 6, 8, 5, 2, 4, 9, 1, 7]
    insertion_sort(nums)
    print('result:', nums)
